package com.xinsoft.controller.basic;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xinsoft.aop.ano.SysLog;
import com.xinsoft.common.BusinessType;
import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.SysReportConfigParam;
import com.xinsoft.entity.po.SysReportConfig;
import com.xinsoft.service.SysReportConfigService;
import com.xinsoft.validator.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName SysReportConfigController
 * @Description 报表配置控制层
 * @Author lijie
 * @Date 2023年11月21日10:07:53
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/report/config")
@Api(value = "SysReportConfigController", tags = {"报表报表配置"})
public class SysReportConfigController {
	@Autowired
	private SysReportConfigService configService;


	/**
	 * @Author Li9527
	 * @Description 报表配置-新增
	 * @Date 2023/5/17 9:57
	 * @params   dept
	 * @return com.xinsoft.common.Response<?>
	 **/
	@SysLog(title = "报表配置-新增", businessType = BusinessType.INSERT)
	@ApiOperation("新增")
	@PostMapping("/add")
	public Response<?> add(@RequestBody SysReportConfig config) {
		// 参数校验
		ValidatorUtils.validateEntity(config);
		SysReportConfig sysReportConfig = configService.getOne(new QueryWrapper<SysReportConfig>().eq("report_key",config.getReportKey()));
		if(sysReportConfig != null){
			return Response.fail("该项配置已存在,请不要重复添加");
		}
		return Response.succeed(configService.save(config));
	}

	/**
	 * @Author Li9527
	 * @Description 更新
	 * @Date 2023/5/17 9:57
	 * @params   dept
	 * @return com.xinsoft.common.Response<?>
	 **/
	@ApiOperation("更新")
	@SysLog(title = "报表配置-编辑", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	public Response<?> edit(@RequestBody SysReportConfig config) {
		// 参数校验
		ValidatorUtils.validateEntity(config);
		return Response.succeed(configService.updateById(config));
	}

	/**
	 * @Author Li9527
	 * @Description 获取详情
	 * @Date 2023/5/17 9:57
	 * @params   id
	 * @return com.xinsoft.common.Response<?>
	 **/
	@ApiOperation("获取详情")
	@GetMapping("/detail")
	public Response<?> detail(@RequestParam(value = "id", defaultValue = "", required = true) Integer id) {
		return Response.succeed(configService.getById(id));
	}

	/**
	 * @Author Li9527
	 * @Description 删除
	 * @Date 2023/5/12 9:20
	 * @params   ids
	 * @return com.xinsoft.common.Response<?>
	 **/
	@ApiOperation("删除")
	@SysLog(title = "报表配置-删除", businessType = BusinessType.DELETE)
	@PostMapping("/del")
	public Response<?> del(@RequestBody List<Integer> ids) {
		configService.removeByIds(ids);
		return Response.succeed();
	}

	/**
	 * @Author Li9527
	 * @Description 通过param_key获取配置对象
	 * @Date 2023/5/17 9:57
	 * @params   id
	 * @return com.xinsoft.common.Response<?>
	 **/
	@ApiOperation("通过reportKey获取配置对象")
	@GetMapping("/getInfoByKey")
	public Response<?> getInfoByKey(@RequestParam(value = "reportKey", defaultValue = "", required = true) String reportKey) {
		return Response.succeed(configService.getOne(new QueryWrapper<SysReportConfig>().eq("report_key",reportKey)));
	}

	/**
	 * @Author Li9527
	 * @Description 报表配置分页
	 * @Date 2023/5/18 10:51
	 * @params   param
	 * @return com.xinsoft.common.Response<?>
	 **/
	@PostMapping("/pageList")
	public Response<?> pageList(@Valid @RequestBody SysReportConfigParam param) {
		return Response.succeed(configService.findPageListByParam(param));
	}
}
